package com.liuyk.broadcast;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;

/**
 * 关闭app的服务
 * <p>
 * Created by Administrator on 2015/9/9.
 */
public class CloseAppBroadcastReceiver extends BaseBroadcastReceiver {

    private static final String ACTION_CLOSE = "android.intent.action.CLOSE_APP";

    public CloseAppBroadcastReceiver() {
    }

    public CloseAppBroadcastReceiver(Context context) {
        super(context);
    }

    @Override
    protected IntentFilter getIntentFilter() {
        return new IntentFilter(ACTION_CLOSE);
    }

    public void closeApp(Context context) {
        final Intent intent = new Intent(ACTION_CLOSE);
        context.sendBroadcast(intent);
    }

    @Override
    public void onReceive(Context context, Intent intent) {
        if (ACTION_CLOSE.equals(intent.getAction())) {
            ((Activity) context).finish();
        }
    }

}
